package group.cyfc.studygo.dao;

import com.sun.org.apache.bcel.internal.generic.Select;
import group.cyfc.studygo.entity.UserRecord;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;

@Repository
public interface UserRecordRepository extends JpaRepository<UserRecord,Long> {

    /**
     * 查找用户是否已有旧版本的关卡记录
     * @param id
     * @param grade
     * @param subject
     * @param is_del
     * @return
     */
    UserRecord findByUserIdAndGradeAndSubjectAndIsDel(Long id,String grade,String subject,Boolean is_del);

    /**
     *
     * 更新用户闯关记录
     * @param id
     * @param gateway_id
     */
    @Modifying
    @Transactional(rollbackOn = Exception.class)
    @Query(nativeQuery = true,value = "update user_record set gateway_id = :gateway_id where id = :id")
    void updateRecord(@Param("id")Long id,@Param("gateway_id")Long gateway_id);
}
